<?php
class AccountPartnerLoginBackAction extends BaseAction
{
    protected $http_method = 'get';
    protected $params = array(
        'code',
    );
    public function __construct($uri)
    {
        parent::__construct($uri);
    }

    protected function logic()
    {
        $tmp = explode('/', $this->uri);
        $partner_name = $tmp[2];
        if($partner_name == 'qq') {
            throw new HttpException('', 202);
        }
        $m = new UserModel();
        $token = $m->getToken($partner_name, $this->input['code']);
        $app_conf = ConfLib::get('app', 'app');
        $deadline = time() + $app_conf['access_token_ttl'];
        setcookie('access_token', $token, $deadline, '/', '.doubanxia.com'); //todo sso www.doubanxia.com
        $this->output['http']['status_code'] = 302;
        $target = '/';
        if(isset($_COOKIE['as'])) {
            $target = $_COOKIE['as'];
        }
        setcookie('as', '', -1, '/accounts');
        $this->output['http']['uri'] = $target;
        return true;
    }
}
?>
